package cmp.compile.panels;

import java.awt.Component;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import cmp.main.Globals;

public class MethodOrthoMCLPanel extends JPanel {
	private static final long serialVersionUID = -721309318079790889L;

	public MethodOrthoMCLPanel(CompilePanel parentPanel) {
		setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		setAlignmentX(Component.LEFT_ALIGNMENT);
		setBackground(Globals.BGCOLOR);
		int width = Globals.CompilePanel.WIDTH;
		add(Box.createVerticalStrut(20));

		// Set defaults in resetSettings()
		
		// Prefix
		JPanel row = CompilePanel.getPanel(true);	
		lblPrefix = new JLabel("Prefix");
		row.add(lblPrefix);
		row.add(Box.createHorizontalStrut(width - lblPrefix.getPreferredSize().width));
		
		txtPrefix = new JTextField(3);
		txtPrefix.setMaximumSize(txtPrefix.getPreferredSize());
		txtPrefix.setMinimumSize(txtPrefix.getPreferredSize());	
		row.add(txtPrefix);
		row.add(Box.createHorizontalStrut(5));
		
		JLabel req = new JLabel("required");
		row.add(req);
		add(row);
		add(Box.createVerticalStrut(10));
		
		// Name
		row = CompilePanel.getPanel(true);
		lblName = new JLabel("Name");
		row.add(lblName);
		row.add(Box.createHorizontalStrut(width - lblName.getPreferredSize().width));
		
		txtName = new JTextField(20);
		txtName.setMaximumSize(txtName.getPreferredSize());
		txtName.setMinimumSize(txtName.getPreferredSize());	
		row.add(txtName);
		add(row);
		add(Box.createVerticalStrut(10));
		
		// Remark
		row = CompilePanel.getPanel(true);
		lblRemark = new JLabel("Remark");
		row.add(lblRemark);
		row.add(Box.createHorizontalStrut(width - lblRemark.getPreferredSize().width));
		
		txtRemark = new JTextField(20);
		txtRemark.setMaximumSize(txtRemark.getPreferredSize());
		txtRemark.setMinimumSize(txtRemark.getPreferredSize());
		row.add(txtRemark);
		row.add(Box.createHorizontalStrut(5));
		
		JLabel eg = new JLabel("e.g. parameters");
		row.add(eg);
		add(row);
		add(Box.createVerticalStrut(10));
		
		// parameters
		row = CompilePanel.getPanel(true);
		lblInflation = new JLabel("Inflation");
		row.add(lblInflation);
		row.add(Box.createHorizontalStrut(width - lblInflation.getPreferredSize().width));
		
		txtInflation = new JTextField(4);
		txtInflation.setText(Globals.Methods.OrthoMCL.INFLATION);
		txtInflation.setMaximumSize(txtInflation.getPreferredSize());
		txtInflation.setMinimumSize(txtInflation.getPreferredSize());			
		row.add(txtInflation);
		add(row);
		add(Box.createVerticalStrut(10));
	
		setMaximumSize(getPreferredSize());
		setMinimumSize(getPreferredSize());
	}
		
	public String getSettings() {
		return  "x:" + txtInflation.getText() + ":x";
	}
		
	public void setSettings(String settings) {
		String [] vals = settings.split(":");
		
		txtInflation.setText(vals[1]);
	}
	
	public void resetSettings() {
		txtName.setText(Globals.Methods.OrthoMCL.TYPE_NAME);
		txtPrefix.setText(Globals.Methods.OrthoMCL.DEFAULT_PREFIX);
		txtRemark.setText("");
		txtInflation.setText(Globals.Methods.OrthoMCL.INFLATION);
	}
	
	public String getMethodName() { return txtName.getText(); }
	public void setMethodName(String name) { txtName.setText(name); }
	
	public String getPrefix() { return txtPrefix.getText(); }
	public void setPrefix(String prefix) { txtPrefix.setText(prefix); }
	
	public static String getMethodType() { return Globals.Methods.OrthoMCL.TYPE_NAME; }
	
	public String getComment() { return txtRemark.getText(); }
	public void setComment(String comment) { txtRemark.setText(comment); }
		
	private JLabel lblName = null;
	private JTextField txtName = null;
	private JLabel lblPrefix = null;
	private JTextField txtPrefix = null;
	private JLabel lblRemark = null;
	private JTextField txtRemark = null;
	private JLabel lblInflation = null;
	private JTextField txtInflation = null;

	public void setLoaded(boolean bLoaded) {
		lblName.setEnabled(!bLoaded);
		txtName.setEnabled(!bLoaded);
		lblPrefix.setEnabled(!bLoaded);
		txtPrefix.setEnabled(!bLoaded);
		lblInflation.setEnabled(!bLoaded);
		txtInflation.setEnabled(!bLoaded);
	}
}
